home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / gempp19.zoo / gem++19 / src / gemr.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-01  |  2.3 KB  |  107 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1992,1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include "gemr.h"
  12. #include "rsc_fix.h"
  13. #include "rsc_gobj.h"
  14. #include <aesbind.h>
  15. #include <stdio.h>
  16. #include <stdlib.h> // For getenv()
  17. #include <support.h> // For findfile()
  18.  
  19. GEMrsc::GEMrsc(const char *filename)
  20. {
  21.     if (rsrc_load((char*)filename)>0) { // XXX - rsrc_load() should take const
  22.         ok=TRUE;
  23.     } else {
  24.         ok=FALSE;
  25.     }
  26.     header=0;
  27. }
  28.  
  29. GEMrsc::GEMrsc(const char *filename, int rscw, int rsch)
  30. // Reimplementation of rsrc_load(filename)
  31. {
  32.     // XXX - should search on $PATH XXX  Or $RSC first maybe?
  33.     FILE* fd=fopen(filename,"rb");
  34.  
  35.     if (!fd) {
  36.         char* path=getenv("RSCPATH"); // My idea.  I think $PATH is a STUPID place.
  37.         if (!path) path=getenv("PATH");
  38.         if (path) {
  39.             char* ext[]={"rsc","RSC",0};
  40.             char* name=findfile((char*)filename,path,ext); // XXX - findfile() should take const
  41.             if (name) {
  42.                 fd=fopen(name,"rb");
  43.             }
  44.         }
  45.     }
  46.  
  47.     ok=FALSE;
  48.  
  49.     if (fd) {
  50.         header=new RSHDR;
  51.         if (fread(header,sizeof(RSHDR),1,fd)==1) {
  52.             int size=header->rsh_rssize-sizeof(RSHDR);
  53.             data=new char[size];
  54.             if (fread(data,1,size,fd)==size) {
  55.                 rsc_fix(header,long(data)-sizeof(RSHDR),rscw,rsch);
  56.                 ok=TRUE;
  57.             } else {
  58.                 delete header;
  59.                 delete data;
  60.             }
  61.         } else {
  62.             delete header;
  63.         };
  64.         fclose(fd);
  65.     }
  66. }
  67.  
  68. GEMrsc::~GEMrsc()
  69. {
  70.     if (ok) {
  71.         if (header) {
  72.             delete header;
  73.             delete data;
  74.         } else {
  75.             rsrc_free();
  76.         }
  77.     }
  78. }
  79.  
  80. GEMrawobject* GEMrsc::Tree(int RSCindex) const
  81. {
  82.     if (!ok) return 0;
  83.  
  84.     GEMrawobject* result=0;
  85.  
  86.     if (header)
  87.         result=(GEMrawobject*)rsc_gobj(header,(long)data-sizeof(RSHDR),R_TREE,RSCindex);
  88.     else
  89.         if (!rsrc_gaddr(R_TREE,RSCindex,&result)) result=0;
  90.  
  91.     return result;
  92. }
  93.  
  94. char* GEMrsc::String(int RSCindex) const
  95. {
  96.     if (!ok) return 0;
  97.  
  98.     char* result=0;
  99.  
  100.     if (header)
  101.         result = (char*)rsc_gobj(header,(long)data-sizeof(RSHDR),R_STRING,RSCindex);
  102.     else
  103.         if (!rsrc_gaddr(R_STRING,RSCindex,&result)) result=0;
  104.  
  105.     return result;
  106. }
  107.